package com.itheima.goods.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.goods.mapper.GoodsMapper;
import com.itheima.goods.pojo.Goods;
import com.itheima.goods.service.GoodsService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.ClientInfoStatus;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @GetMapping("")
    public Result findAll(){

        return goodsService.findAll();
    }


    @PostMapping("")
    public Result add(@RequestBody Goods goods){
        return goodsService.add(goods);
    }

    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        return goodsService.findPage(page,size);
    }
    @PostMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size,@RequestBody Goods goods){
        return goodsService.findPage(page,size,goods);
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        return goodsService.findById(id);
    }
    @PutMapping("/{id}")
    public Result update(@PathVariable("id")Integer id,@RequestBody Goods goods){
        return goodsService.update(id,goods);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id")Integer id){
        return goodsService.delete(id);
    }
}
